<?php

class Admin_QuestionController extends Zend_Controller_Action
{
	public function indexAction()
	{
		$task = $this->_helper->getHelper("TaskList");

		$service = new QuestionService();
		$task->setService($service);
		
		$task->registerTask("search","ask");
		
		$data = $task->doTask();

		$gui = $this->_helper->getHelper("Gui");
		$gui->setToolbar(array('new','edit','delete'), My_Translate::translate("QUESTION_MANAGER"));
		$gui->showData($data);
	}

	public function createAction()
	{
		$service = new QuestionService();
		if ($this->getRequest()->isPost ()) {
			if($service->store())
			{
				$this->_redirect("/admin/question/index");exit;
			}
			else
			{
				$this->view->errorList = $service->getErrorMsg();
				$this->view->question = $_POST;
			}
		}
		else
		{
			$id = $this->_getParam("id");
			$title = My_Translate::translate("QUESTION_ADD");
			if(!empty($id))
			{
				$title = My_Translate::translate("QUESTION_EDIT");
				$this->view->question = $service->loadData($id);
			}
		}
		
		$gui = $this->_helper->getHelper("Gui");
		$gui->setToolbar(array('save','cancel'),$title);
	}

}